<template>
	<view class="content">
		<view class="tips">{{$t("order.collectionVoucherTips")}}</view>
		<view>
			<view class="title">{{$t("order.collectionVoucher")}}</view>
			<u-upload :action="action" ref='upload' :header="headers" @on-success="(res)=> uploadImg(res, 0)"
				@on-remove="(index)=>deletePic(index,0)" name="multipart" :max-count="1" :show-progress="false"
				:file-list="fileListImg" :upload-text="$t('order.addTo')">
			</u-upload>
		</view>
		<view class="tips">
			{{$t("order.collectionVoucherTips1")}}
		</view>
		<button type="primary" @click="sumbit" class="button">{{$t("order.submit")}}</button>
	</view>
</template>

<script>
	let app = getApp();
	import {
		mapGetters
	} from "vuex";
	import {
		HTTP_REQUEST_URL,
		TOKENNAME
	} from "@/config/app";

	import {
		confirmOrderOffline,
	} from '@/api/order.js';
	export default {
		data() {
			return {
				action: "",
				headers: "",
				fileListImg: [],
				dataObj: {
					id: '',
					receiptVoucher: '',
					type: true
				},
				flag:true
			}
		},
		computed: mapGetters(["token", "merId"]),
		onLoad(option) {
			this.action = `${HTTP_REQUEST_URL}api/admin/upload/oss/image?model=content&pid=0`;
			this.headers = {
				[TOKENNAME]: this.token,
			};
			var _this = this
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.on('acceptDataFromOpenerPage', function(data) {
				_this.dataObj.id = data.id
			})
		},
		onShow() {
			uni.setNavigationBarTitle({
				title: this.$t('navigation.confirmReceipt')
			});
		},
		methods: {
			uploadImg(res, type, index) {
				console.info(res)
				this.dataObj.receiptVoucher = res.data.url
			},
			deletePic(index, type, index1) {
				this.dataObj.receiptVoucher = ''
			},
			sumbit() {
				let _this = this
				if (!this.flag){
					return
				}
				this.flag = false
				confirmOrderOffline(this.dataObj).then((res) => {
					this.$util.Tips({
						title: this.$t("publicLang.successfulOperation")
					});
					setTimeout(function() {
						_this.flag = true
						const eventChannel = _this.getOpenerEventChannel();
						eventChannel.emit('someEvent', {
							data: ''
						});
						uni.navigateBack()
					}, 1500);
				}).catch(e=>{
					_this.flag = true
				});

			}
		}
	}
</script>

<style lang="scss">
	.content {
		background-color: #FFFFFF;
		padding: 20rpx;
	}

	.title {
		margin: 10rpx;
		font-size: 30rpx;
	}

	.tips {
		font-weight: bold;
	}

	.button {
		margin-top: 40rpx;
		height: 80rpx;
		line-height: 80rpx;
	}
</style>
